<template>
  <header>
    <div class="l-content">
      <el-button
        plain
        icon="el-icon-menu"
        size="mini"
        @click="handleMenu"
      ></el-button>
      <!-- <h3 style="color: #fff">首页</h3> -->
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: item.path }" v-for="item in tag" :key="item.path">{{item.label}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown trigger="click" size="mini">
        <span>
          <img :src="userImg" alt="用户头像" class="user" />
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>个人中心</el-dropdown-item>
          <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </header>
</template>

<script>
import { mapState } from "vuex"

export default {
  name: "CommonHeader",
  data() {
    return {
      userImg: require("@/assets/img/logo.png"),
    };
  },
  computed: {
    ...mapState({
      tag: state => state.tab.tabsList
    })
  },
  methods: {
    handleMenu() {
      this.$store.commit("collapseMenu");
    },
    logout(){
      this.$store.commit("clearToken");
      this.$store.commit("clearMenu");
      this.$router.push("/login")
    }
  },
};
</script>

<style lang="less" scoped>
header {
  display: flex;
  height: 100%;
  justify-content: space-between;
  align-items: center;

  .el-breadcrumb-item {
    color: "#fff"
  }

  .l-content {
    display: flex;
    align-items: center;

    .el-button {
      margin-right: 20px;
    }
  }

  .r-content {
    display: flex;
    align-items: center;

    .user {
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }

    .el-dropdown-link {
      cursor: pointer;
      color: #409eff;
    }
    .el-icon-arrow-down {
      font-size: 12px;
    }
  }
}
</style>